package leetcode.weekly.week309;

//Solution1Test
public class Solution1 {

	public boolean checkDistances(String s, int[] distance) {
		char[] cs = s.toCharArray();
		boolean[] check = new boolean[26];
		for (int i = 0; i < cs.length; i++) {
			int index = cs[i] - 'a';
			if (!check[index]) {
				int d = distance[index];
				check[index] = true;
				int next = i + d + 1;
				if (next >= cs.length) {
					return false;
				}
				int n = cs[next] - 'a';
				if (index != n) {
					return false;
				}
				distance[index] = 0;
			}
		}
		return true;
	}
}
